﻿<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>arrObj.splice(起点,要删除的个数,要插入的数据)</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
            font-family: "微软雅黑", "张海山锐线体简"
        }
    </style>
    <script>
        //arrObj.splice(起点,要删除的个数,要插入的数据);
        var arr = ['龙', '虎', '斗'];
        var result = arr.splice(1, 2, '野', '鸡'); //插入	要删除的个数=0  插入的数据可以插入多个,也可以没有
        console.log(arr);
        console.log(result);//['虎','斗'] 返回一个新数组，值是删除的数据

        var arr2 = ['龙', '虎', '斗'];
        arr2.splice(arr2.length, 0, '无');//模拟push，尾部推入
        console.log(arr2); //["龙", "虎", "斗", "无"]
        arr2.splice(arr.length, 1); //pop，头部删除
        console.log(arr2);//["龙", "虎", "斗"]
        arr2.splice(0, 0, '间'); // unshift
        console.log(arr2); //["间", "龙", "虎", "斗"]
        arr2.splice(0, 1); //shift
        console.log(arr2);//["龙", "虎", "斗"]
    </script>
</head>

<body>
</body>

</html>
